package com.wave.wavesystem.ai.app;

import com.wave.wavesystem.ai.test.docquery.RagCustomAdvisorFactory;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.stereotype.Component;


@Component
public class LoveApp {


    @Resource
    private ChatClient waveChatClient;

    @Resource
    private VectorStore wavePgVectorStore;

    public String doChatWithRag(String message, String chatId) {
        ChatResponse chatResponse = waveChatClient.prompt()
                .user(message)
                .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, chatId)
                        .param("chatsize", 10))
                .advisors(new SimpleLoggerAdvisor())
                .advisors(
                        RagCustomAdvisorFactory.createRagCustomAdvisorFactory(wavePgVectorStore, 2)
                ).call().chatResponse();

        return chatResponse.getResult().getOutput().getText();
    }

    public String doChatWithMCP(String message, String chatId) {
        ChatResponse chatResponse = waveChatClient.prompt()
                .user(message)
                .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, chatId)
                        .param("chatsize", 10))
                .advisors(new SimpleLoggerAdvisor())
                .advisors(
                        RagCustomAdvisorFactory.createRagCustomAdvisorFactory(wavePgVectorStore, 2)
                ).call().chatResponse();

        return chatResponse.getResult().getOutput().getText();
    }


}
